| Conditions | 1 |
| Paths | 1 |
| Total Lines | 95 |
| Code Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import chai, { expect } from 'chai'; |
||
| 10 | describe('Search', () => { |
||
| 11 | let spotify; |
||
| 12 | let fetchedStub; |
||
| 13 | |||
| 14 | beforeEach( () => { |
||
| 15 | spotify = new SpotifyWrapper({ |
||
| 16 | token: 'foo' |
||
| 17 | }); |
||
| 18 | |||
| 19 | fetchedStub = sinon.stub(global, 'fetch'); |
||
| 20 | fetchedStub.resolves({ json: () => {} }); |
||
| 21 | }); |
||
| 22 | |||
| 23 | afterEach( () => { |
||
| 24 | fetchedStub.restore(); |
||
| 25 | }); |
||
| 26 | |||
| 27 | describe('smoke tests', () => { |
||
| 28 | it('should exist the spotify.search.albums method', () => { |
||
| 29 | expect(spotify.search.albums).to.exist; |
||
|
|
|||
| 30 | }); |
||
| 31 | |||
| 32 | it('should exist the spotify.search.artists method', () => { |
||
| 33 | expect(spotify.search.artists).to.exist; |
||
| 34 | }); |
||
| 35 | |||
| 36 | it('should exist the spotify.search.tracks method', () => { |
||
| 37 | expect(spotify.search.tracks).to.exist; |
||
| 38 | }); |
||
| 39 | |||
| 40 | it('should exist the spotify.search.playlists method', () => { |
||
| 41 | expect(spotify.search.playlists).to.exist; |
||
| 42 | }); |
||
| 43 | }); |
||
| 44 | |||
| 45 | describe('spotify.search.artists', () => { |
||
| 46 | it('should call fetch function', () => { |
||
| 47 | spotify.search.artists('Incubus'); |
||
| 48 | expect(fetchedStub).to.have.been.calledOnce; |
||
| 49 | }); |
||
| 50 | |||
| 51 | it('should call fetch with the correct URL', () => { |
||
| 52 | spotify.search.artists('Incubus'); |
||
| 53 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Incubus&type=artist') |
||
| 54 | |||
| 55 | spotify.search.artists('Muse'); |
||
| 56 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Muse&type=artist') |
||
| 57 | }); |
||
| 58 | }); |
||
| 59 | |||
| 60 | describe('spotify.search.albums', () => { |
||
| 61 | it('should call fetch function', () => { |
||
| 62 | spotify.search.albums('Incubus'); |
||
| 63 | expect(fetchedStub).to.have.been.calledOnce; |
||
| 64 | }); |
||
| 65 | |||
| 66 | it('should call fetch with the correct URL', () => { |
||
| 67 | spotify.search.albums('Incubus'); |
||
| 68 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Incubus&type=album') |
||
| 69 | |||
| 70 | spotify.search.albums('Muse'); |
||
| 71 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Muse&type=album') |
||
| 72 | }); |
||
| 73 | }); |
||
| 74 | |||
| 75 | describe('spotify.search.tracks', () => { |
||
| 76 | it('should call fetch function', () => { |
||
| 77 | spotify.search.tracks('Incubus'); |
||
| 78 | expect(fetchedStub).to.have.been.calledOnce; |
||
| 79 | }); |
||
| 80 | |||
| 81 | it('should call fetch with the correct URL', () => { |
||
| 82 | spotify.search.tracks('Incubus'); |
||
| 83 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Incubus&type=track') |
||
| 84 | |||
| 85 | spotify.search.tracks('Muse'); |
||
| 86 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Muse&type=track') |
||
| 87 | }); |
||
| 88 | }); |
||
| 89 | |||
| 90 | describe('spotify.search.playlists', () => { |
||
| 91 | it('should call fetch function', () => { |
||
| 92 | spotify.search.playlists('Incubus'); |
||
| 93 | expect(fetchedStub).to.have.been.calledOnce; |
||
| 94 | }); |
||
| 95 | |||
| 96 | it('should call fetch with the correct URL', () => { |
||
| 97 | spotify.search.playlists('Incubus'); |
||
| 98 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Incubus&type=playlist') |
||
| 99 | |||
| 100 | spotify.search.playlists('Muse'); |
||
| 101 | expect(fetchedStub).to.have.been.calledWith('https://api.spotify.com/v1/search?q=Muse&type=playlist') |
||
| 102 | }); |
||
| 103 | }); |
||
| 104 | }); |
||
| 105 |